package com.xszx.system.controller;

import com.xszx.server.dto.AjaxJson;
import com.xszx.server.dto.Page;
import com.xszx.server.entity.Resource;
import com.xszx.server.service.ResourceService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/resource")
public class ResourceController {
    @javax.annotation.Resource
    private ResourceService resourceService;

    @GetMapping("/getAllResources")
    public AjaxJson getAllResources(){
        return AjaxJson.success().put("resources",resourceService.getAllResources());
    }

    @GetMapping("/getResource")
    public AjaxJson getResource(String id){
        return AjaxJson.success().put("resources",resourceService.getResource(id));
    }

    @PostMapping("/save")
    public AjaxJson save(@RequestBody String resourceStr){
        resourceService.saveResources(resourceStr);
        return AjaxJson.success("资源更新成功");
    }
    @GetMapping("/deleteResource")
    public AjaxJson deleteResource(String id){
        int result = resourceService.del(id);
        if(result>0){
            return AjaxJson.success("删除成功");
        }else{
            return AjaxJson.error("删除失败");
        }
    }
}
